
function fval = solve_1s_2c_private_notForRamsey(xval,taux,taf)

global L n alpha  d rbest delta1 theta1

% guess wage and share of labor in each sector

w(1:n,1) = xval(1:n); % row vector
taf = 0;

r1 = log(rbest);
rL(1,1)= exp(r1)*L(1);
rL(2,1)= rbest*L(2);

% rL
% alpha
% delta


T = alpha.*rL/delta1;

sextax = zeros(n);
for i=1:n-1
    sextax(i+1) = taux;
end
staf = zeros(n);

for i=1:n-1
    staf(i+1) = taf;
end

pi = zeros(n,n); % (1,2,3): country 2 export to ecountry 1 in sector 3, NOTE country order is opposite to our note
%d, matrix of n times n, dij country j ship to country i


xnimatrix1= T'.*((w'.*(1+sextax).*(1+staf).*d).^(-theta1));
 xn1 =sum(xnimatrix1,2).*ones(n,n);

pimatrix1 = xnimatrix1./xn1;
pi = pimatrix1;
xnimatrix= xnimatrix1;

betas = 1;
x  =  (1+theta1)/theta1*w.*(L-sum(rL,2));

extax1 = sextax;
for m=2:n
    x(1)=x(1)+betas(1)*taux/(1+taux)*pi(m,1)*x(m);
end
tempt=0;
for m=2:n
    tempt=tempt+betas(1)*taf/(1+taf)*pi(1,m);
end

x(1)=x(1)/(1-tempt);

P=(sum(xnimatrix1,2)).^(-betas./theta1);

fval(1) = P(1)-1;
fval(2) = pi(1,2)*x(1)-pi(2,1)*x(2);
